// pages/remind/remind.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageRoot: app.globalData.imageRoot,
    remind:[],
    page_token: 0,
    fileList: [
      // {url:'https://img.yzcdn.cn/vant/leaf.jpg'}
    ],
    myl: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  query(data) {
    let that = this;
    getApp().ports.api34({data}).then((res) => {
      console.log(res, "------------------------collection")
      let datalist = res.data;
      datalist.results.forEach(item => {
        if(item.favoriteType == 1){
          item.banner = item.foreclosedHouse.banner;
          if(!item.tags){
            let tags = [];
            tags.push({name:item.foreclosedHouse.builtUpAreaSquareCentimeter.toFixed(2)+"m²"})
            tags.push({name:item.foreclosedHouse.discountRate.toFixed(2)+"折"})
            if(item.foreclosedHouse.stage) tags.push({name:item.foreclosedHouse.stage})
            item.tags = tags
          }
          item.marketPriceYuan = Math.floor(item.foreclosedHouse.marketPriceYuan/10000)
          item.estimatePriceYuan = Math.floor((item.foreclosedHouse.estimatePriceYuan / 10000));
          item.priceYuan = Math.floor(item.foreclosedHouse.priceYuan/10000)
        }else{
          item.banner = that.data.imageRoot + item.discountHouse.banner;
          if(!item.tags){
            let tags = [];
            tags.push({name:item.discountHouse.builtUpAreaSquareCentimeter.toFixed(2)+"m²"})
            tags.push({name:item.discountHouse.discountRate.toFixed(2)+"折"})
            if(item.discountHouse.stage) tags.push({name:item.discountHouse.stage})
            item.tags = tags
          }
          item.marketPriceYuan = Math.floor(item.discountHouse.marketPriceYuan)
          item.estimatePriceYuan = Math.floor((item.discountHouse.estimatePriceYuan));
          item.priceYuan = Math.floor(item.discountHouse.priceYuan);
        }

        if(that.data.page_token >= 1){
          that.data.remind.results.push(item)
        }
      })
      if (that.data.page_token >= 1) {
        datalist.results = that.data.remind.results
      }
      this.setData({remind: datalist ,myl: false  })
      
      // if (that.data.page_token >= 1) {
      //   datalist.results.forEach(item => {
      //     if(!item.tags){
      //       let tags = [];
      //       tags.push({name:item.built_up_area_square_centimeter.toFixed(2)+"m²"})
      //       tags.push({name:item.discount_rate.toFixed(2)+"折"})
      //       if(item.stage) tags.push({name:item.stage})
      //       item.tags = tags
      //     }
      //     if(item.type == 1){
      //       item.market_price_yuan = Math.floor(item.market_price_yuan/10000)
      //       item.price_yuan = Math.floor(item.price_yuan/10000)
      //     }    
      //     that.data.remind.results.push(item)
      //   })
      //   datalist.results = that.data.remind.results
      // }else{
      //   datalist.results.forEach(item => {
      //     if(!item.tags){
      //       let tags = [];
      //       tags.push({name:item.built_up_area_square_centimeter.toFixed(2)+"m²"})
      //       tags.push({name:item.discount_rate.toFixed(2)+"折"})
      //       if(item.stage) tags.push({name:item.stage})
      //       item.tags = tags
      //     }
      //     if(item.type == 1){
      //       item.market_price_yuan = Math.floor(item.market_price_yuan/10000)
      //       item.price_yuan = Math.floor(item.price_yuan/10000)
      //     }    
      //   })
      // }
      
    }).catch((error) => {
      console.log(error)
    })
  },
  onLoad: function (options) {
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline']
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: app.globalData.color,
    })
    // for(let i = 0;i<1;i++){
    // let datas = {  discount_house_id:"9012d5d3-1115-4d28-a91a-040c8b4b9196"}
    // getApp().ports.api344({data:datas}).then((res) => {
    //   console.log(res)
    // }).catch((error)=>{console.log(error)});
    // }
    let data = { page_size: 10,page_token: this.data.page_token }
    this.query(data)
  },
  getdata(e){ //删除后刷新
    // console.log(e, '-----------1-1-1-1-1')
    if(e.detail.code == 200){
      this.query()
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.query({});
    this.setData({
      page_token:0
    })
    setTimeout(()=>{
      wx.stopPullDownRefresh()
      console
    },1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  // onReachBottom: function () {

  // },
  onReachBottom() { //上拉加载更多
    var that = this;
    //检查是否还有数据可以加载
    var total_size = that.data.remind.total;
    var size = that.data.remind.results.length;
    var page_token = that.data.page_token += 1; //每次下拉，页码加1
    //如果还有，则继续加载
    if (total_size > size) {
      var data = {
        page_token: page_token,
        page_size: 10
      }
      // that.data.Loading = wx.showLoading({ title: '加载中',  })
      that.query(data)
      // console.log(size, data)
      //如果没有了，则停止加载，显示没有更多内容了
    } else {
      that.setData({
        myl: true
      })
    }
    that.setData({
      Loading: that.data.Loading
    })
  },
  
})